<?php
namespace app\index\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Request;

class Course extends Base
{
   
    public function index()
    {
    $cate_id=input('cate_id');
    $searchkey=input('searchkey');
     $where=[];//筛选条件数组
     if(input('cate_id')){
        $where[] = [
                     ['cate_id', '=', $cate_id],
                 ];
     }

     if(input('searchkey')){
        $where[] = [
                     ['title', 'like', '%'.$searchkey.'%'],
                 ];
     }    
  $listdata= $data=Db::name('course')-> where($where)->paginate([
              'list_rows'=> 20,//每页数量
              'query' => request()->param(),
              ]);
  
        return view('',[
        'cate_id'=>$cate_id,
            'listdata'=>$listdata,
        ]);
    }

 
    public function article(){
     
    $id=input('id');
    $login =session('userAccount'); 
    $archivesData=Db::name('course')->where('id',$id)->find();
    if($archivesData['power']==0){
         return view('',[
        'archivesData'=>$archivesData,
        'loginsf'=>$login['username'],
        ]); 
    }elseif ($archivesData['power']==1) {
        if(!$login) {
         return alert('未登录不能查看本教程，请登录查看，将为您跳转至登录页','Location: /index/login',6,3);    
   
        }else{
         return view('',[
        'archivesData'=>$archivesData,
        'loginsf'=>$login['username'],
        ]);    
        }// code...
    }elseif ($archivesData['power']==2){
        if(!$login) {
       return alert('未登录不能查看本教程，请登录查看，将为您跳转至登录页','Location: /index/login',6,3);
        }else {
   
     $userdata=  Db::name('users')->where('id',$login['id'])->find();
     $orderdata= Db::name('order')->where('uid',$login['id'])->where('status','>=',1)->where('webid',$archivesData['yuanmaid'])->find();
             if($orderdata !== NULL){
                 return view('',[
                 'archivesData'=>$archivesData,
                 'loginsf'=>$login['username'],
                 ]);  
             }else{
                  return alert('未购买源码不能查看教程，将为您跳转到源码购买页面','/index/index/product?id='.$archivesData['yuanmaid'],6,3);
               
             }
   
     
      
    }
    }
    
   


 }
  


    
  
}
